import java.util.*;
import java.lang.*;
public class MyBC{
    String Normal;
    String Behind= ""; //后序表示
    int countLeft=0,countRight=0;
    public void setNormal(String str){
        Normal=str;
        Behind="";
    }
    public void change(){
        Stack stack=new Stack();
        int opValue []=new int[100];
        for (int i=0;i<Normal.length() ;i++) {
            char chi=Normal.charAt(i);
            if (chi>='0'&&chi<='9'){ //数字直接输出
                Behind=Behind+chi;
            }
            else if (chi=='+'||chi=='-'||chi=='*'||chi=='÷'||chi=='/') { //如果是运算符的话：
                Behind=Behind+" ";
                if (stack.empty()){ //若栈为空，入栈
                    stack.push(chi);
                }
                else if (Value(chi)>Value((char)stack.peek())) { //若栈不空，那么比较优先级，如果优先级比栈顶元素高，入栈
                    stack.push(chi);
                }
                else{
                    Behind=Behind+ String.valueOf(stack.pop())+" ";//否则出栈输出
                    i--;
                }
            }
            else if(chi=='('){
                countLeft++;
                stack.push(chi);//左括号直接压栈
            }
            else if(chi==')'){ //如果遇到右括号，不停出栈并输出直到遇到左括号，把左括号出栈
                Behind+=" ";
                countRight++;
                while((char)stack.peek()!='('){
                    Behind=Behind+ String.valueOf(stack.pop())+" ";
                }
                stack.pop();
            }
        }
        Behind+=" ";
        while(!stack.empty()){
            Behind=Behind+String.valueOf(stack.pop())+" ";
        }
    }
    public int Value(char c){ //设定不同运算符的优先级
        int value=0;
        switch(c){
            case '(':
                value=1;
                break;
            case '+':
            case '-':
                value=2;
                break;
            case '*':
            case '÷':
                value=3;
                break;
            case '/':
                value=4;
                break;
            case ')':
                value=5;
            default:
                value=0;
        }
        return value;
    }
}

